package com.ofood.springcloud.controller;

import com.ofood.springcloud.domain.Food;
import com.ofood.springcloud.domain.Result;
import com.ofood.springcloud.service.FoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class FoodController {
    @Resource
    private FoodService foodService;

    @Value("${server.port}")
    private String port;

    @PostMapping("/consul/food/create")
    public Result create(@RequestBody Food food){
        int result=foodService.create(food);

        if(result>0){
            return new Result(200,"成功"+";server port:"+port,result);
        }else {
            return new Result(500,"失败",null);
        }
    }

    @GetMapping("/consul/food/get/{foodId}")
    public Result getFoodById(@PathVariable("foodId") long foodId){
        Food food=foodService.getFoodById(foodId);

        if(food!=null){
            return new Result(200,"成功"+";server port:"+port,food);
        }else {
            return new Result(500,"失败",null);
        }
    }
}